home *** CD-ROM | disk | FTP | other *** search
/ ftp.anonawest.com / ftp.anonawest.com.tar / ftp.anonawest.com / Memorial Day+TAPS_files / ylib_list.js < prev   
Text File  |  2013-02-25  |  4KB  |  139 lines

  1. /*
  2.  | create your own build method to fit your menu design
  3.  |
  4.  | send questions to jchu@yahoo-inc.com
  5.  */
  6.  
  7. /*
  8.  | constructor
  9.  | param: id - an identifier, w - width of the menu
  10.  */ 
  11. function ylib_List(id, w) {
  12.  this.name=id;
  13.  this.id = id+'_List';
  14.  eval(this.id+"=this");
  15.  
  16.  this.menu = null;
  17.  this.items = new Array();
  18.  this.h = 0;
  19.  this.w = w;
  20.  this.isOpen = 0;
  21.  this.multiSelect = 0;
  22.  this.isChild = 0;
  23.  this.selectedIdx = null;
  24.  this.pmenuIdx = null;
  25.  this.pmenuItemIdx = null;
  26.  this.lnk = '';
  27.  this.css = '';
  28.  this.div = '';
  29.  this.color = new Object();
  30.  
  31.  this.add      = ylib_listAdd;
  32.  this.init     = ylib_listInit;
  33.  this.over     = ylib_listOver;
  34.  this.out      = ylib_listOut;
  35.  this.down     = ylib_listDown; 
  36.  this.select   = ylib_listSelect;
  37.  this.deselect = ylib_listDeselect;
  38.  this.turnOn   = ylib_listTurnOn;
  39.  this.turnOff  = ylib_listTurnOff ;
  40.  this.sLink    = ylib_listSetLink;
  41.  this.onSelect = new Function();
  42.  this.build    = new Function();
  43. }
  44.  
  45. /*
  46.  | items (array) [text, value]
  47.  | p - parent menu index, index instead of object b/c of performance concern
  48.  | idx - parent menu item index
  49.  */
  50. function ylib_listAdd(items,p,idx) {
  51.  if (items==null) return;
  52.  if (p!=null) {
  53.    this.pmenuIdx = p;
  54.    this.pmenuItemIdx = idx;
  55.    this.isChild=1;
  56.  }
  57.  var l = items.length;
  58.  for (var i=0; i<l; i++) {
  59.    this.items[i] = new Array();
  60.    this.items[i].selected = 0;
  61.    this.items[i].hasChild = 0;
  62.    this.items[i].childIdx = -1;
  63.    this.items[i].text = items[i][0];
  64.    this.items[i].value = items[i][1];
  65.    this.items[i].lnk = '<a href="'+items[i][1]+'"  onfocus="'+this.id+'.over('+i+')" onblur="'+this.id+'.out('+i+')">'+items[i][0]+'</a>';
  66.    this.items[i].y = this.h;
  67.    this.h += this.itemH;
  68.  } 
  69. }
  70.  
  71. function ylib_listInit() {
  72.   // activate each item
  73.   var oItem=null;
  74.   this.handle = ylib_getObj(this.id+this.handle);
  75.   for (var i=0; i<this.items.length; i++) {
  76.     oItem = ylib_getObj(this.id+i);
  77.     // set mouseevents
  78.     ylib_addEvt(oItem, "mouseover", new Function(this.id+".over("+i+")"),false);
  79.     ylib_addEvt(oItem, "mouseout", new Function(this.id+".out("+i+")"),false);
  80.     if (oBw.ns) oItem.captureEvents(Event.MOUSEDOWN) // needed for ns4
  81.       ylib_addEvt(oItem, "mousedown", new Function(this.id+".down("+i+")"),false);
  82.   }
  83. }
  84.  
  85. function ylib_listOver(idx) {
  86.   if (this.menu&&this.menu.hideTimerID!=null) { clearTimeout(this.menu.hideTimerID); this.menu.hideTimerID=null; }
  87.   if (!this.items[idx].selected) { this.turnOn(ylib_getObj(this.id+idx));    }
  88.  
  89.   if (this.isOpen && idx!=this.selectedIdx) {
  90.     if (this.menu!=null) this.menu.hide(this); // close menus when rolling over other items in the parent menu
  91.     this.deselect(this.selectedIdx);
  92.     if (this.items[idx].hasChild) this.select(idx);
  93.   }
  94. }
  95.  
  96. function ylib_listOut(idx) {
  97.  if (!this.items[idx].selected) { this.turnOff(ylib_getObj(this.id+idx)) }
  98.  if (this.isChild) this.menu.hideMenu();
  99. }
  100.  
  101. function ylib_listDown(idx) { 
  102.  window.location.href = this.items[idx].value;
  103.  return false;
  104. }
  105.  
  106. function ylib_listSelect(idx) {
  107.   var oItem = this.items[idx]
  108.   if (oItem==null) return;
  109.   oItem.selected = 1;
  110.   this.selectedIdx = idx;
  111.   this.onSelect(ylib_getObj(this.id+idx));
  112. }
  113.  
  114. function ylib_listDeselect(idx) {
  115.   oItem = this.items[idx];
  116.   if (oItem==null) return;
  117.   oItem.selected = 0;
  118.   this.turnOff(ylib_getObj(this.id+idx));
  119.   this.selectedIdx = null
  120. }
  121.  
  122. function ylib_listTurnOn(o) {
  123.  ylib_setStyle(o,"backgroundColor",this.color.onBg);
  124.  this.sLink(o,true);
  125. }
  126.  
  127. function ylib_listTurnOff(o) {
  128.  ylib_setStyle(o,"backgroundColor",this.color.offBg);
  129.  this.sLink(o,false);
  130. }
  131.  
  132. function ylib_listSetLink(o,isOver) {
  133.  if(oBw.win && (oBw.ie||oBw.dom)) {
  134.   lnk=o.getElementsByTagName("a");
  135.   lnk[0].style.textDecorationUnderline=isOver;
  136.   this.lnk= (isOver)? lnk[0].href:"";
  137.  }
  138. }
  139.